package org.mspring.mlog.dao.impl;

import java.util.List;

import org.mspring.mlog.dao.CommentDao;
import org.mspring.mlog.entity.Comment;
import org.mspring.platform.dao.hibernate.GenericDao;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Gao Youbo
 * @since 2014-01-11
 */
@Repository
public class CommentDaoImpl extends GenericDao<Comment, Long> implements CommentDao {

    @Override
    public void updateStatus(long id, String status) {
        super.executeUpdate("update Comment comment set comment.status = ? where comment.id = ?", status, id);
    }

    @Override
    public List<Comment> listByPost(long postId) {
        return super.list("select comment from Comment comment where comment.post.id = ?", postId);
    }

    @Override
    public List<Comment> listByPostAndStatus(long postId, String status) {
        return super.list("select comment from Comment comment where comment.post.id = ? and comment.status = ?", postId, status);
    }

    @Override
    public long countComment() {
        return getHibernateTemplate().count("select count(*) from Comment comment where comment.status = ?", Comment.Status.APPROVED);
    }

}
